<template>
  <div class="mobile-config">
    <el-form ref="formInline">
      <div v-for="(item, key) in rCom" :key="key">
        <component
          :is="item.components.name"
          :configObj="configObj"
          ref="childData"
          :configNme="item.configNme"
          :index="activeIndex"
          :num="item.num"
        ></component>
      </div>
      <rightBtn :activeIndex="activeIndex" :configObj="configObj"></rightBtn>
    </el-form>
  </div>
</template>

<script>
import toolCom from '@/components/mobileConfigRight/index.js'
import rightBtn from '@/components/rightBtn/index.vue'
import { mapMutations } from 'vuex'

export default {
  name: 'c_home_section',
  componentsName: 'home_section',
  cname: '首页组合区块',
  props: {
    activeIndex: { type: null },
    num: { type: null },
    index: { type: null }
  },
  components: {
    ...toolCom,
    rightBtn
  },
  data() {
    return {
      configObj: {},
      rCom: [
        { components: toolCom.c_tab, configNme: 'tabConfig' },
        { components: toolCom.c_input_item, configNme: 'titleConfig' },
        { components: toolCom.c_bg_color, configNme: 'titleColor' },
        { components: toolCom.c_is_show, configNme: 'showMore' },
        { components: toolCom.c_slider, configNme: 'mbConfig' }
      ]
    }
  },
  watch: {
    num(nVal) {
      const value = JSON.parse(JSON.stringify(this.$store.state.mobildConfig.defaultArray[nVal]))
      this.configObj = value
    },
    configObj: {
      handler(nVal) {
        this.$store.commit('mobildConfig/UPDATEARR', { num: this.num, val: nVal })
      },
      deep: true
    },
    'configObj.tabConfig.tabVal': {
      handler(nVal) {
        if (nVal === 0) {
          // 标题配置
          this.rCom = [
            { components: toolCom.c_tab, configNme: 'tabConfig' },
            { components: toolCom.c_input_item, configNme: 'titleConfig' },
            { components: toolCom.c_bg_color, configNme: 'titleColor' },
            { components: toolCom.c_is_show, configNme: 'showMore' },
            { components: toolCom.c_slider, configNme: 'mbConfig' }
          ]
        } else if (nVal === 1) {
          // Banner配置
          this.rCom = [
            { components: toolCom.c_tab, configNme: 'tabConfig' },
            { components: toolCom.c_menu_list, configNme: 'bannerSwiperConfig' },
            { components: toolCom.c_is_show, configNme: 'bannerIsShow' },
            { components: toolCom.c_bg_color, configNme: 'bannerBgColor' },
            { components: toolCom.c_slider, configNme: 'bannerLrConfig' }
          ]
        } else if (nVal === 2) {
          // Menu配置
          this.rCom = [
            { components: toolCom.c_tab, configNme: 'tabConfig' },
            { components: toolCom.c_menu_list, configNme: 'menuListConfig' },
            { components: toolCom.c_txt_tab, configNme: 'menuStyle' },
            { components: toolCom.c_bg_color, configNme: 'menuBgColor' }
          ]
        }
      },
      deep: true
    }
  },
  mounted() {
    this.$nextTick(() => {
      const value = JSON.parse(JSON.stringify(this.$store.state.mobildConfig.defaultArray[this.num]))
      this.configObj = value
    })
  }
}
</script>

<style scoped lang="scss">
/* 配置面板样式 */
.mobile-config {
  padding: 15px;
}
.title-tips {
  padding-bottom: 10px;
  color: #333;
  span {
    margin-right: 14px;
    color: #999;
  }
}
</style>